package com.xyz.app.shiro;

import com.auth0.jwt.JWT;
import com.auth0.jwt.JWTVerifier;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.exceptions.JWTVerificationException;
import com.free.ext.logger.FreeLogger;
import com.free.ext.logger.FreeLoggerFactory;
import com.xyz.domain.model.UserSessionModel;
import com.xyz.shiro.exception.JwtException;
import com.xyz.shiro.jwt.JwtTools;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.credential.CredentialsMatcher;

import java.io.UnsupportedEncodingException;

public class JWTCredentialsMatcher implements CredentialsMatcher {

    private static final FreeLogger LOGGER = FreeLoggerFactory.getLogger(JWTCredentialsMatcher.class);

    @Override
    public boolean doCredentialsMatch(AuthenticationToken authenticationToken, AuthenticationInfo authenticationInfo) {
        return false;
//
//        UserSessionModel user = (UserSessionModel)authenticationInfo.getPrincipals().getPrimaryPrincipal();
//        try {
//            Algorithm algorithm = Algorithm.HMAC256(salt);
//            JWTVerifier verifier = JWT.require(algorithm)
//                    .withClaim(JwtTools.JWT_ACCOUNT, user.getUserName())
//                    .build();
//            verifier.verify(token);
//            return true;
//        } catch (UnsupportedEncodingException e) {
//            LOGGER.info("JWTCredentialsMatcher 发生[UnsupportedEncodingException]异常{}", e);
//            throw new JwtException(JwtException.EnumJwtExceptionType.UnSupportEncoding,"编码格式不支持",e);
//        } catch (JWTVerificationException e){
//            LOGGER.info("JWTCredentialsMatcher 发生[JWTVerificationException]异常{}", e);
//            throw new JwtException(JwtException.EnumJwtExceptionType.DecodeFail,"验证失败",e);
//        }
    }

}
